﻿@model RTW.OA.Models.role
@{
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}

@section styles{
<style>
    .tree-list .col-1 {
        padding-left: 1%;
        width: 20%;
    }

    .tree-list .col-2 {
        width: 70%;
    }

    .tree-list .col-3 {
        width: 10%;
        text-align: center;
    }
</style>
}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="ibox-title">
                <h4>@ViewBag.Title </h4>
            </div>
            <div class="ibox-content">
                @using (Html.BeginForm("Edit", "Role", FormMethod.Post, new { area = "System", id = "roleform", name = "roleform" }))
                {
                    @Html.AntiForgeryToken()
                    @Html.HiddenFor(m => m.ROLE_ID)
                    @*@Html.HiddenFor(m => m.FUNC_ID_MENU)*@
                    @Html.HiddenFor(m => m.FUNC_ID_STR)
                    @Html.HiddenFor(m => m.FUNC_ACTION_STR)
                    <div class="from-content">
                        <dl>
                            <dt>所属部门</dt>
                            <dd>
                                <div class="rule-single-select">
                                    @Html.DropDownListFor(model => model.ROLE_DEPT_ID, ViewBag.TreeData as List<SelectListItem>, new { @Class = "form-control", datatype = "*", sucmsg = " " })
                                </div>
                            </dd>
                        </dl>
                        <dl>
                            <dt>角色名称</dt>
                            <dd>

                                @Html.EditorFor(model => model.ROLE_NAME, new { htmlAttributes = new { @class = "input normal form-control", datatype = "*2-100", sucmsg = " " } })

                            </dd>
                        </dl>
                        <dl>
                            <dt>角色代码</dt>
                            <dd>
                                @Html.EditorFor(model => model.ROLE_NO, new { htmlAttributes = new { @class = "input normal form-control", datatype = "*2-100", sucmsg = " " } })

                            </dd>
                        </dl>

                        <dl>
                            <dt>全局角色</dt>
                            <dd>
                                <div class="rule-single-checkbox">
                                    @Html.CheckBoxFor(m => m.IS_GLOBAL, new { @class = "form-control" })
                                </div>
                            </dd>
                        </dl>
                        <dl>
                            <dt>管理权限</dt>
                            <dd>

                                <div id="BUTTONFUNC" class="tree-list">
                                    <div class="thead">
                                        <div class="col col-1">导航名称</div>
                                        <div class="col col-2">权限分配</div>
                                        <div class="col col-3">全选</div>
                                    </div>
                                    <ul>
                                        @*@if(Model.FUNC_ID_MENU!=null)
                                {*@
                                        @for (int i = 0; i < Model.FUNC_ID_MENU.Count; i++)
                                        {
                                            <li class="layer-@(Model.FUNC_ID_MENU[i].LEVEL.Value+1) ">
                                                <div class="tbody">
                                                    <div class="col index col-1">
                                                        @*<asp:HiddenField ID="hidName" Value='@Model.FUNC_ID_MENU[i].MENU_NAME' runat="server" />
                                                <asp:HiddenField ID="hidActionType" Value='@Model.FUNC_ID_MENU[i].IS_SYS' runat="server" />*@
                                                        @Model.FUNC_ID_MENU[i].MENU_NAME
                                                    </div>
                                                    <div class="col col-2">
                                                        @*<asp:CheckBoxList ID="cblActionType" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="cbllist"></asp:CheckBoxList>*@
                                                        @if (Model.FUNC_ID_MENU[i].MENU_ACTION != null)
                                                        {
                                                        <span id="rptList_cblActionType_@Model.FUNC_ID_MENU[i].MENU_ID" class="cbllist ">
                                                            @for (int j = 0; j < Model.FUNC_ID_MENU[i].MENU_ACTION.Count; j++)
                                                            {
                                                                var actionid = Model.FUNC_ID_MENU[i].MENU_ACTION[j].PERMISSION_ID;
                                                                var text = Model.FUNC_ID_MENU[i].MENU_ACTION[j].PERMISSION_NAME;
                                                                var code = Model.FUNC_ID_MENU[i].MENU_ACTION[j].PERMISSION_CODE;
                                                                var type = Model.FUNC_ID_MENU[i].MENU_ACTION[j].TYPE;
                                                         
                                                                <input id="rptList_cblActionType_@actionid" type="checkbox" name="rptList$@Model.FUNC_ID_MENU[i].MENU_ID$cblActionType$0" value=@actionid>

                                                                <label for="rptList_cblActionType_@actionid"  style="border: 1px solid #ccc!important;padding:3px;border-radius: 5px!important;">
                                                                    @if (type == 1)
                                                                    {
                                                                        <i class="iconfont icon-lianjie"></i>
                                                                    }
                                                                    @if (type == 2)
                                                                    {
                                                                        <i class="iconfont icon-function"></i>
                                                                    }
                                                                    @if (type == 3)
                                                                    {
                                                                        <i class="iconfont icon-anniu"></i>
                                                                    }
                                                                    @text
                                                                </label>
                                                            
                                                            }
                                                        </span>
                                                        }
                                                    </div>
                                                    <div class="col col-3">
                                                        <input name="checkAll" type="checkbox" />
                                                    </div>
                                                </div>
                                            </li>
                                        }
                                        @*}*@
                                    </ul>
                                </div>
                            </dd>
                        </dl>
                    
                    </div>
                    <div class="from-footer">
                        <div class="btn-wrap" style="position: fixed;">
                            <a class="btn btn-sm btn-primary radius" onclick="savefrom()">
                                <i class="iconfont icon-save"></i>
                                提交保存
                            </a>
                            <a class="btn btn-sm btn-warning radius">
                                <i class="iconfont icon-fanhui"></i>
                                取消关闭
                            </a>
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="@Url.Content("~/Content/JS/common/WdatePicker/WdatePicker.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/jquery/Validform_v5.3.2_min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/artdialog/dialog-plus-min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/JS/common/webuploader/webuploader.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.config.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/ueditor.all.min.js")"></script>
    <script type="text/javascript" charset="utf-8" src="@Url.Content("~/Content/editor/lang/zh-cn/zh-cn.js")"></script>
    @*<script type="text/javascript" charset="utf-8" src="../js/uploader.js"></script>*@
    <script src="@Url.Content("~/Content/JS/common/from.js")"></script>

    <script>
        $(function () {
            //初始化表单验证
            $("#roleform").initValidform();

            //初始化分类的结构
            initCategoryHtml('.tree-list', 1);
            //初始化分类的事件
            $('.tree-list').initCategoryTree(true);
            ////是否启用权限
            //if ($("#ddlRoleType").find("option:selected").attr("value") == 1) {
            //    $(".tree-list").find("input[type='checkbox']").prop("disabled", true);
            //}
            //$("#ddlRoleType").change(function () {
            //    if ($(this).find("option:selected").attr("value") == 1) {
            //        $(".tree-list").find("input[type='checkbox']").prop("checked", false);
            //        $(".tree-list").find("input[type='checkbox']").prop("disabled", true);
            //    } else {
            //        $(".tree-list").find("input[type='checkbox']").prop("disabled", false);
            //    }
            //});
            //权限单选
            $(".tree-list").find("input[type='checkbox']").click(function () {
                if ($(this).prop("checked") != true) {
                    if ($(this).siblings().is(':checked')) {
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("indeterminate", true);
                    } else {
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("indeterminate", false);
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("checked", false);
                    }
                } else {
                    if ($(this).siblings().is(':checked')) {
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("indeterminate", false);
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("checked", true);
                    } else {
                        $(this).parent().parent().siblings(".col").find("input[name='checkAll']").prop("indeterminate", true);
                    }
                }
            })
            //权限全选
            $("input[name='checkAll']").click(function () {
                if ($(this).prop("checked") == true) {
                    $(this).parent().siblings(".col").find("input[type='checkbox']").prop("checked", true);
                } else {
                    $(this).parent().siblings(".col").find("input[type='checkbox']").prop("checked", false);
                }
            });
        });
        function savefrom() {
            let funcstr = ",";
            $("#BUTTONFUNC").find("input[type='checkbox']").each(function () {
                if ($(this).is(':checked')) {
                    var v = $(this).val()
                    if (v != 'on') {
                        funcstr += v + ",";
                    }
                }
            })
            //var str = funcstr.substring(0, funcstr.length - 1)
            $("#FUNC_ID_STR").val(funcstr);
            //funcstr = "";
            //$("#ACTIONFUNC").find("input[type='checkbox']").each(function () {
            //    if ($(this).is(':checked')) {
            //        var v = $(this).val()
            //        if (v != 'on') {
            //            funcstr += v + ",";
            //        }
            //    }
            //})
            //$("#FUNC_ACTION_STR").val(funcstr);
            $("#roleform").submit();
        }
    </script>
}

